//
//  LivingCell.m
//  FKGW
//
//  Created by song ce on 2017/3/1.
//  Copyright © 2017年 song ce. All rights reserved.
//

#import "LivingCell.h"
#import "OSSHelper.h"
@implementation LivingCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    //显示位置的label
    self.loactionLabel = [[UILabel alloc]initWithFrame:CGRectZero];
    self.loactionLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:12];
    self.loactionLabel.textColor = DEF_COLOR102;
    [self addSubview:self.loactionLabel];
    
    self.loactionImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"zhibodingwei"]];
    [self addSubview:self.loactionImageView];
    
    
//    NSString *loaction = @"石家庄裕华区";
//    self.loactionLabel.text = loaction;
//    CGRect frame = [loaction boundingRectWithSize:CGSizeMake(180, 21) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12]} context:nil];
//    CGFloat with = CGRectGetWidth(frame);
//    self.loactionLabel.frame = CGRectMake(Main_Screen_Width-with-15, 7, with, 21);
//    self.loactionImageView.frame = CGRectMake(Main_Screen_Width-with-15-10-8, 12, 8, 11);
    
    self.nameLabel.font = [UIFont  fontWithName:@"PingFangSC-Medium" size:14];
    self.onlineCoutLabel.font = [UIFont fontWithName:@"PingFangSC-Regular" size:11];
}


-(void)setModel:(LiveStoreModel *)model{
    _model = model;
    self.nameLabel.text = _model.storeName;
    self.introduceLabel.text = _model.storeIntroduce;
    self.onlineCoutLabel.text = [NSString stringWithFormat:@"%@ 在看",_model.popularity];
    //店铺地址
    CGFloat with = [self labelWidthWithContent:_model.storeAddress];
    self.loactionLabel.frame = CGRectMake(Main_Screen_Width-with-15, 7, with, 21);
    self.loactionImageView.frame = CGRectMake(Main_Screen_Width-with-15-10-8, 12, 8, 11);

    //店铺头像
    self.shopIcon.image = [UIImage imageNamed:@"zhibo_touxian_t"];
    [[OSSHelper sharedHelper]OSSDownLoadWithObjectKey:_model.storeHeader xOssProcess:[NSString stringWithFormat:@"image/resize,m_lfit,w_%d,h_%d",36,36]  downLoadBlock:^(NSData *data) {
        dispatch_async(dispatch_get_main_queue(), ^{
            self.shopIcon.image= [UIImage imageWithData:data];
        });
    }];
    //店铺封面
//   self.storepic.image = [UIImage imageNamed:@"zhibo_touxian_t"];
    [[OSSHelper sharedHelper]OSSDownLoadWithObjectKey:_model.storePics xOssProcess:[NSString stringWithFormat:@"image/resize,m_lfit,w_%d,h_%d",(int)Main_Screen_Width,259]  downLoadBlock:^(NSData *data) {
        dispatch_async(dispatch_get_main_queue(), ^{
            self.storepic.image= [UIImage imageWithData:data];
        });
    }];

}

- (IBAction)liveButton:(UIButton *)sender {
        if(![AppDelegate appDealegate].uid.length){
            LoginViewController *login = [[LoginViewController alloc]init];
            login.isModel = YES;
            BaseNavigationViewController *baseNavi = [[BaseNavigationViewController alloc]initWithRootViewController:login];
            [[self baseViewController] presentViewController:baseNavi animated:YES completion:nil];
            return;
        }
    if(self.clickBlock){
        self.clickBlock();
    }
}
- (BaseViewController*)baseViewController{
    UIResponder *next = self.nextResponder;
    while (next!=nil) {
        if([next isKindOfClass:[BaseViewController class]]){
            return (BaseViewController*)next;
        }
        next = next.nextResponder;
    }
    return nil;
}

-(CGFloat)labelWidthWithContent:(NSString*)content{
    CGRect frame = [content boundingRectWithSize:CGSizeMake(180, 21) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12]} context:nil];
    CGFloat with = CGRectGetWidth(frame);
    if(Main_Screen_Width-with-15-10-8>self.nameLabel.right+10){
        return with;
    }
    return Main_Screen_Width-self.nameLabel.right-10-15-10-8;
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}

@end
